package com.anti.modular.bus.houseleaselive.controller;

import com.anti.commom.annotation.BusinessLog;
import com.anti.commom.annotation.Permission;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.commom.api.Result;
import com.anti.jdbc.support.page.PageParam;
import com.anti.modular.bus.houseleaselive.param.HouseLeaseLiveParam;
import com.anti.modular.bus.houseleaselive.service.HouseLeaseLiveService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 房间租约同住人控制器
 *
 * @author anti
 * @date 2021-05-06 12:22:22
 */
@RestController
@RequestMapping("houseLeaseLive")
public class HouseLeaseLiveController {

    @Resource
    private HouseLeaseLiveService houseLeaseLiveService;

    /**
     * 查询房间租约同住人
     *
     * @author anti
     * @date 2021-05-06 12:22:22
     */
    @GetMapping("page")
    @BusinessLog(title = "房间租约同住人_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result page(PageParam pageParam, HouseLeaseLiveParam houseLeaseLiveParam) {
        return Result.data(houseLeaseLiveService.page(pageParam,houseLeaseLiveParam));
    }

    /**
     * 添加房间租约同住人
     *
     * @author anti
     * @date 2021-05-06 12:22:22
     */
    @Permission
    @PostMapping("add")
    @BusinessLog(title = "房间租约同住人_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(HouseLeaseLiveParam.add.class) HouseLeaseLiveParam houseLeaseLiveParam) {
            houseLeaseLiveService.add(houseLeaseLiveParam);
        return Result.success("新增成功");
    }

    /**
     * 删除房间租约同住人
     *
     * @author anti
     * @date 2021-05-06 12:22:22
     */
    @Permission
    @PostMapping("delete")
    @BusinessLog(title = "房间租约同住人_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(HouseLeaseLiveParam.delete.class) HouseLeaseLiveParam houseLeaseLiveParam) {
            houseLeaseLiveService.delete(houseLeaseLiveParam);
        return Result.success("删除成功");
    }

    /**
     * 编辑房间租约同住人
     *
     * @author anti
     * @date 2021-05-06 12:22:22
     */
    @Permission
    @PostMapping("edit")
    @BusinessLog(title = "房间租约同住人_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(HouseLeaseLiveParam.edit.class) HouseLeaseLiveParam houseLeaseLiveParam) {
            houseLeaseLiveService.edit(houseLeaseLiveParam);
        return Result.success("修改成功");
    }

    /**
     * 查看房间租约同住人
     *
     * @author anti
     * @date 2021-05-06 12:22:22
     */
    @GetMapping("detail")
    public Result detail(@Validated(HouseLeaseLiveParam.detail.class) HouseLeaseLiveParam houseLeaseLiveParam) {
        return Result.data(houseLeaseLiveService.detail(houseLeaseLiveParam));
    }

    /**
     * 房间租约同住人列表
     *
     * @author anti
     * @date 2021-05-06 12:22:22
     */
    @GetMapping("list")
    public Result list(HouseLeaseLiveParam houseLeaseLiveParam) {
        return Result.data(houseLeaseLiveService.list(houseLeaseLiveParam));
    }

    /**
     * 查看房间租约同住人
     *
     * @author anti
     * @date 2021-05-06 12:22:22
     */
    @GetMapping("getTzrListByLeaseId/{leaseId}")
    public Result getTzrListByLeaseId(@PathVariable(name = "leaseId") Long leaseId) {
        return Result.data(houseLeaseLiveService.getTzrListByLeaseId(leaseId));
    }
}
